<template>
  <view class="bottom-nav-demo">
    <!-- 页面内容 -->
    <view class="demo-content">
      <view class="demo-header">
        <text class="demo-title">底部导航演示</text>
        <text class="demo-subtitle">H5端底部导航组件展示</text>
      </view>
      
      <!-- 主题选择 -->
      <view class="theme-selector">
        <text class="section-title">主题选择</text>
        <view class="theme-options">
          <view 
            v-for="theme in themes" 
            :key="theme.value"
            class="theme-option"
            :class="{ 'theme-option--active': currentTheme === theme.value }"
            @click="changeTheme(theme.value)"
          >
            <view class="theme-color" :style="{ backgroundColor: theme.color }"></view>
            <text class="theme-name">{{ theme.name }}</text>
          </view>
        </view>
      </view>
      
      <!-- 导航配置 -->
      <view class="nav-config">
        <text class="section-title">导航配置</text>
        <view class="config-item">
          <text class="config-label">固定定位</text>
          <switch :checked="navConfig.fixed" @change="updateConfig('fixed', $event.detail.value)" />
        </view>
        <view class="config-item">
          <text class="config-label">安全区域</text>
          <switch :checked="navConfig.safeArea" @change="updateConfig('safeArea', $event.detail.value)" />
        </view>
        <view class="config-item">
          <text class="config-label">显示徽章</text>
          <switch :checked="navConfig.showBadge" @change="updateConfig('showBadge', $event.detail.value)" />
        </view>
        <view class="config-item">
          <text class="config-label">显示红点</text>
          <switch :checked="navConfig.showDot" @change="updateConfig('showDot', $event.detail.value)" />
        </view>
      </view>
      
      <!-- 当前页面显示 -->
      <view class="current-page">
        <text class="section-title">当前页面</text>
        <view class="page-info">
          <text class="page-name">{{ currentPageInfo.text }}</text>
          <text class="page-path">{{ currentPageInfo.pagePath }}</text>
        </view>
      </view>
      
      <!-- 模拟内容区域 -->
      <view class="mock-content">
        <text class="section-title">模拟内容区域</text>
        <view class="content-cards">
          <view class="content-card" v-for="i in 5" :key="i">
            <text class="card-title">内容卡片 {{ i }}</text>
            <text class="card-desc">这是模拟的内容区域，用于展示底部导航的固定效果</text>
          </view>
        </view>
      </view>
    </view>
    
    <!-- 底部导航 -->
    <bottom-nav
      :items="navItems"
      :current="currentNavIndex"
      :fixed="navConfig.fixed"
      :safe-area="navConfig.safeArea"
      :theme="currentTheme"
      @change="handleNavChange"
    />
  </view>
</template>

<script>
import BottomNav from '@/components/bottom-nav/bottom-nav.vue'

export default {
  name: 'BottomNavDemo',
  components: {
    BottomNav
  },
  data() {
    return {
      currentNavIndex: 0,
      currentTheme: 'blue',
      themes: [
        { name: '蓝色', value: 'blue', color: '#0A2463' },
        { name: '橙色', value: 'orange', color: '#FF6B35' },
        { name: '绿色', value: 'green', color: '#00C851' },
        { name: '紫色', value: 'purple', color: '#8B5CF6' }
      ],
      navConfig: {
        fixed: true,
        safeArea: true,
        showBadge: true,
        showDot: true
      },
      navItems: [
        {
          text: '首页',
          iconText: '🏠',
          pagePath: '/pages/index/index',
          badge: '',
          dot: false
        },
        {
          text: '智能评估',
          iconText: '🤖',
          pagePath: '/pages/smart-evaluation/index',
          badge: '',
          dot: false
        },
        {
          text: '工具',
          iconText: '🛠️',
          pagePath: '/pages/tools/index',
          badge: '3',
          dot: false
        },
        {
          text: '进度',
          iconText: '📊',
          pagePath: '/pages/progress-tracking/index',
          badge: '',
          dot: true
        },
        {
          text: '我的',
          iconText: '👤',
          pagePath: '/pages/personal-center/index',
          badge: '',
          dot: false
        }
      ]
    }
  },
  computed: {
    currentPageInfo() {
      return this.navItems[this.currentNavIndex] || this.navItems[0]
    }
  },
  methods: {
    changeTheme(theme) {
      this.currentTheme = theme
    },
    updateConfig(key, value) {
      this.navConfig[key] = value
      
      // 更新导航项配置
      if (key === 'showBadge') {
        this.navItems = this.navItems.map((item, index) => ({
          ...item,
          badge: value && index === 2 ? '3' : ''
        }))
      }
      
      if (key === 'showDot') {
        this.navItems = this.navItems.map((item, index) => ({
          ...item,
          dot: value && index === 3
        }))
      }
    },
    handleNavChange(event) {
      this.currentNavIndex = event.index
      console.log('导航切换:', event)
    }
  },
  onLoad() {
    // 设置导航栏标题
    uni.setNavigationBarTitle({
      title: '底部导航演示'
    })
  }
}
</script>

<style lang="scss" scoped>
.bottom-nav-demo {
  min-height: 100vh;
  background: #f5f7fa;
  padding-bottom: 80px; // 为固定底部导航留出空间
}

.demo-content {
  padding: 20px;
}

.demo-header {
  text-align: center;
  margin-bottom: 30px;
  padding: 20px;
  background: linear-gradient(135deg, #0A2463 0%, #1E3A8A 100%);
  border-radius: 16px;
  color: white;
  
  .demo-title {
    display: block;
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
  }
  
  .demo-subtitle {
    display: block;
    font-size: 14px;
    opacity: 0.9;
  }
}

.section-title {
  display: block;
  font-size: 18px;
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 16px;
}

.theme-selector {
  margin-bottom: 30px;
  padding: 20px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.theme-options {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.theme-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 16px;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  
  &:hover {
    border-color: #0A2463;
    transform: translateY(-2px);
  }
  
  &--active {
    border-color: #0A2463;
    background: rgba(10, 36, 99, 0.05);
  }
}

.theme-color {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  margin-bottom: 8px;
}

.theme-name {
  font-size: 12px;
  color: #6b7280;
  font-weight: 500;
}

.nav-config {
  margin-bottom: 30px;
  padding: 20px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.config-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid #f3f4f6;
  
  &:last-child {
    border-bottom: none;
  }
}

.config-label {
  font-size: 14px;
  color: #374151;
  font-weight: 500;
}

.current-page {
  margin-bottom: 30px;
  padding: 20px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.page-info {
  padding: 16px;
  background: #f8fafc;
  border-radius: 8px;
  border-left: 4px solid #0A2463;
}

.page-name {
  display: block;
  font-size: 16px;
  font-weight: 600;
  color: #0A2463;
  margin-bottom: 4px;
}

.page-path {
  display: block;
  font-size: 12px;
  color: #6b7280;
  font-family: 'Courier New', monospace;
}

.mock-content {
  padding: 20px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.content-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.content-card {
  padding: 16px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  
  .card-title {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 4px;
  }
  
  .card-desc {
    display: block;
    font-size: 12px;
    color: #6b7280;
    line-height: 1.4;
  }
}

// 响应式设计
@media (max-width: 480px) {
  .demo-content {
    padding: 16px;
  }
  
  .theme-options {
    gap: 8px;
  }
  
  .theme-option {
    padding: 8px 12px;
  }
  
  .theme-color {
    width: 20px;
    height: 20px;
  }
  
  .theme-name {
    font-size: 11px;
  }
}

@media (min-width: 768px) {
  .demo-content {
    max-width: 800px;
    margin: 0 auto;
  }
  
  .theme-options {
    justify-content: center;
  }
  
  .content-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }
}

// 深色模式支持
@media (prefers-color-scheme: dark) {
  .bottom-nav-demo {
    background: #111827;
  }
  
  .demo-content {
    .section-title {
      color: #f9fafb;
    }
  }
  
  .theme-selector,
  .nav-config,
  .current-page,
  .mock-content {
    background: #1f2937;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }
  
  .config-item {
    border-bottom-color: #374151;
  }
  
  .page-info {
    background: #111827;
  }
  
  .content-card {
    background: #111827;
    border-color: #374151;
  }
}
</style>